package com.tsingteng.cosfun.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetTypeUtil {

    public static int checkNetworkConnection(Context context) {
        boolean wifiConnected = false;
        boolean mobileConnected = false;
        int type = -1;
        ConnectivityManager connMgr =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
        if (activeInfo != null && activeInfo.isConnected()) {
            wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
            mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
            if (wifiConnected) {
                type = 1;
            } else if (mobileConnected) {
                type = 0;
            }
        } else {
            type = -1;
        }
        return type;
    }

}
